<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			
			
		
			window.onload=function(){
			//1、修改给个th  td的颜色
				var tName=document.getElementsByTagName("table");
				for (var i=0;i<5;i++) {
					var trName=tName[0].getElementsByTagName("tr")[0].getElementsByTagName("th")[i];
					if(i==0){
						trName.style.background="blue";
					}else if(i==1){
						trName.style.background="red";
					}else if(i==2){
						trName.style.background="violet";
					}else if(i==3){
						trName.style.background="forestgreen";
					}else if(i==4){
						trName.style.background="cornflowerblue";
					}
					
				}
				
					//奇数行为蓝色，偶数行为红色(js代码生成)
					var taName=document.getElementsByTagName("table")[0];
					for (var i=0;i<3;i++) {
						var newTr=document.createElement("tr");
							taName.appendChild(newTr);
						for (var j=0;j<5;j++) {		
							var newTd=document.createElement("td")
							newTr.appendChild(newTd);
							for (var k=0;k<1;k++) {
								var newText=document.createTextNode("你好");
								newTd.appendChild(newText);
							}
						}
					}
					
					for (var i=1;i<4;i++) {
						var taName1=document.getElementsByTagName("table")[0].getElementsByTagName("tr")[i];
						if(i%2!=0){
							taName1.style.color="blue";
							
						}else{
							taName1.style.color="red";
						}
					}
				
					
					
				
			
				
							
				
				
				
					
			}
			
		</script>
	</head>
	<body>
		<table border="1">
				<tr>
					<th class="" >部门名称</th>
					<th class="">部门电话</th>
					<th class="">部门负责人</th>
					<th class="">所属单位</th>
					<th class="">操作</th>
				</tr>
			
		</table>
		
	</body>
</html>
